package com.lipstick.activities;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

import com.lipstick.app.Calculator;
import com.lipstick.app.R;

public class MainActivity extends Activity implements OnSeekBarChangeListener {
	private SeekBar sbDesconto;
	private TextView tvDesc;
	private TextView tvFullPrice;
	private EditText etPreco;
	private Calculator calculator;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		/*
		 * If device changes its orientation (portrait/landscape), this method is called again.
		 * */
		if (sbDesconto == null) {
			//sbDesconto = (SeekBar) findViewById(R.id.sbDesconto);
			sbDesconto.setOnSeekBarChangeListener(this);
			//tvDesc = (TextView) findViewById(R.id.tvDesconto);
			tvFullPrice = (TextView) findViewById(R.id.tvPrecoOriginal);
			etPreco = (EditText) findViewById(R.id.edtPreco);
			calculator = Calculator.getInstance();
		}
	}

	@Override
	public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
		tvDesc.setText(progress + "%");
		calculator.setDiscount(progress);
		if (calculator.getFullPrice() == 0){
			calculator.setFullPrice(Float.parseFloat(etPreco.getText().toString()));
			tvFullPrice.setText("Valor Original: R$ "+calculator.getFullPrice());
		}
		calculator.setDiscount(progress);
		etPreco.setText(String.valueOf(calculator.getFinalPrice()));
	}

	@Override
	public void onStartTrackingTouch(SeekBar seekBar) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onStopTrackingTouch(SeekBar seekBar) {

	}

}
